package com.tian.common.strategy;


import com.tian.common.enums.CouponUseTypeEnum;
import com.tian.common.factory.ApplicationContextFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * {@code @description:} 策略有实现类关联
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-11-19 22:22
 * {@code @version:} 1.0
 */
public class CalculateDiscountAmountStrategy {
    private final static Map<Integer, Class<? extends CalculateDiscountAmountService>> DISCOUNT_AMOUNT_MAP = new HashMap<>();

    static {
        DISCOUNT_AMOUNT_MAP.put(CouponUseTypeEnum.CASH.getType(), CalculateDiscountAmount4DeductionServiceImpl.class);
        DISCOUNT_AMOUNT_MAP.put(CouponUseTypeEnum.DISCOUNT.getType(), CalculateDiscountAmount4DiscountServiceImpl.class);
        DISCOUNT_AMOUNT_MAP.put(CouponUseTypeEnum.FULL_REDUCE.getType(), CalculateDiscountAmount4FullReduceServiceImpl.class);
    }

    public static CalculateDiscountAmountService getCalculateDiscountAmountService(Integer couponUseType) {
        return ApplicationContextFactory.getBean(DISCOUNT_AMOUNT_MAP.get(couponUseType));
    }

}
